<?php

namespace App\Http\Controllers\Admin;

use App\Exports\PhoneLogExport;
use App\Http\Controllers\Controller;
use App\Models\Phonemap;
use App\Models\Users;
use Illuminate\Http\Request;
use Maatwebsite\Excel\Facades\Excel;

class PhoneMapController extends Controller {

    /**
     * 页面
     * @return view
     */
    public function index(){
        return view('admin.demand.phone_map');
    }

    /**
     * 列表数据
     * @param Request $request
     * @return bool
     */
    public function list(Request $request){
        try{
            $params = [
                'kwd' => (string)$request->get('kwd',''),
                'connet_status' => $request->get('connet_status'),
            ];
            $lists = Phonemap::getList($params);
            foreach ($lists as $key => $val){
                $lists[$key]['aname'] = Users::where('mobile',$val['anumber'])->value('username');
                $lists[$key]['bname'] = Users::where('mobile',$val['bnumber'])->value('username');
            }
            return $this->writeJson(0,$lists);
        }catch (\Exception $e){
            return $this->writeJson(1,null,$e->getMessage());
        }
    }

    /**
     *  Excel导出
     * @param Request $request
     * @return bool
     */
    public function exports(Request $request)
    {
        $ids = $request->get('ids');
        $export = new PhoneLogExport($ids);
        //这里可以传参到服务层
        return Excel::download($export, '通话记录表'.date("Y-m-d H:i:s").'.xlsx');
    }


}
